'''
Created on 25-10-2011

@author: 7
'''
import xml.sax

class MetadataProcessor(xml.sax.handler.ContentHandler):

    def __init__(self, replaceWith, out):
        xml.sax.handler.ContentHandler.__init__(self)
        self._out = out
        self._replaceWith = replaceWith

    # ContentHandler methods
        
    def startDocument(self):
        self._out.write('<?xml version="1.0" ?>\n<!DOCTYPE DjVuXML>\n')
    def startElement(self, name, attrs):
        self._out.write('<' + name)
        for (name, value) in attrs.items():
            self._out.write(' %s="%s"' % (name, value))
        self._out.write('>')

    def endElement(self, name):
        self._out.write('</%s>' % name)

    def characters(self, content):
        self._out.write(content)

    def ignorableWhitespace(self, content):
        self._out.write(content)
        
    def processingInstruction(self, target, data):
        self._out.write('<?%s %s?>' % (target, data))